// pages/default/default.js
var util = require('../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navindex: 0,
    According: false,
    freightnav: [
      { txt: '违约申请' },
      { txt: '违约记录' },

    ],
    apply:[
      // { num: '12345612345', numapp: '12345612345', name: '巴啦啦', types: '承运方延迟承运，货主同意', price: '1000' },
      // { num: '12345612345', numapp: '12345612345', name: '巴啦啦', types: '承运方延迟承运，货主同意', price: '1000' },
      // { num: '12345612345', numapp: '12345612345', name: '巴啦啦', types: '承运方延迟承运，货主同意', price: '1000' },
      // { num: '12345612345', numapp: '12345612345', name: '巴啦啦', types:'承运方延迟承运，货主同意',price:'1000'},
    ],
    currentPage: 1,
    totalPage: 1,
    status:0
  },
  click: function (e) {
    var id = e.currentTarget.dataset.id;
    console.log(id)
    this.setData({
      navindex: id,
      status:id,
      currentPage:1,
      apply:[]
    })
    this.initData()
  },
  initData: function () {
    var that = this;
    var param = {
      currentPage: that.data.currentPage,
      status: that.data.status
    };
    wx.hideLoading();
    util.commonRequest('applyBreachRecord', 'post',param, function (res) {
      wx.hideLoading();
      var data = res.data;
      if (data.code == 200) {
        var tempArr = data.data.data;
        var oriArr = that.data.apply;
        var finalyArr = oriArr.concat(tempArr);
        that.setData({
          apply : finalyArr,
          totalPage: data.data.last_page
        })
        if (finalyArr.length == 0){
          that.setData({
            According: true,
          })
        } else{
          that.setData({
            According: false,
          })
        }
      

      } else {
        wx.showToast({
          icon: 'loading',
          title: data.msg,
        })
      }
    });
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var currentpage = this.data.currentPage;
    var totalpage = this.data.totalPage;
    if (currentpage < totalpage) {
      this.setData({
        currentPage: currentpage + 1
      })
      this.initData();
    } else {
      console.log("已经是全部数据")
      // wx.showToast({
      //   'icon':'loading',
      //   title: '已经是全部数据了',
      // })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})